import type { TableColumn } from '@/framework/components/core/super-table';
import dayjs from 'dayjs';
import { Tag } from 'ant-design-vue';

export type TableListItem = {
  id;
  editType;
  name;
  key;
  valueType;
  memo;
  sortIndex;
  fieldRequired;
  createTime;
};
export type TableColumnItem = TableColumn<TableListItem>;

// 字段类型
export const typeMap = {
  0: '普通文本',
  1: '整数',
  2: '小数',
  3: '日期时间',
  4: '枚举',
};
export const baseColumns: TableColumnItem[] = [
  {
    type: 'seq',
    title: '序号',
    width: 60,
  },
  {
    title: '字段类型',
    field: 'editType',
    slots: {
      default: ({ row }) => {
        return <Tag color={row.editType === 1 ? 'red' : 'blue'}>{row.editType === 1 ? '系统字段' : '扩展字段'}</Tag>;
      },
    },
    hideInSearch: true,
  },
  {
    title: '字段名称',
    field: 'name',
  },
  {
    title: '字段标识',
    field: 'key',
    hideInSearch: true,
  },
  {
    title: '字段类型',
    field: 'valueType',
    formatter: ({ cellValue }) => {
      return typeMap[cellValue];
    },
    hideInSearch: true,
  },
  {
    title: '描述',
    field: 'memo',
    hideInSearch: true,
  },
  {
    title: '排序权重',
    field: 'sortIndex',
    hideInSearch: true,
  },
  {
    title: '是否必填',
    field: 'fieldRequired',
    formatter: ({ cellValue }) => {
      return cellValue === 1 ? '是' : '否';
    },
    hideInSearch: true,
  },
  {
    title: '使用时间',
    field: 'createTime',
    formatter: ({ cellValue }) => {
      return cellValue ? dayjs(cellValue).format('YYYY-MM-DD HH:mm:ss') : '-';
    },
    hideInSearch: true,
  },
];
